

<template>
  <div class="register">
    <div class="back-btn" @click="onLogin">
      返回
      <el-icon><Back /></el-icon>
    </div>

    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="auto"
      class="register-ruleForm"
      size="default"
      status-icon
    >
      <el-form-item label="用户名：" prop="name">
        <el-input v-model="ruleForm.name" />
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input v-model="ruleForm.password" />
      </el-form-item>
      <el-form-item label="确认密码：" prop="confirmPassword">
        <el-input v-model="ruleForm.confirmPassword" />
      </el-form-item>
      <el-form-item label="手机号：" prop="phone">
        <el-input v-model="ruleForm.phone" />
      </el-form-item>

      <el-form-item label="性别：" prop="sex">
        <el-radio-group v-model="ruleForm.sex">
          <el-radio value="1">男</el-radio>
          <el-radio value="0">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="年龄：" prop="age">
        <el-input v-model="ruleForm.age" />
      </el-form-item>
      <el-form-item label="头像：">
        <UploadFile></UploadFile>
      </el-form-item>

      <el-form-item class="tool-content">
        <el-button type="primary" @click="onRegister(ruleFormRef)"
          >注 册{{ posterTotal }}</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
  
  <script setup lang='ts'>
import { reactive, ref } from "vue";
import UploadFile from "@/components/login/UploadFile";
import type { FormInstance, FormRules } from "element-plus";
import { Back } from "@element-plus/icons-vue";
import { useLoginStore } from "@/stores/modules/login"; //路径别名，引入store
const { setState } = useLoginStore();

interface IRuleForm {
  name: string;
  password: string;
  confirmPassword: string;
  phone: string;
  rememberMe: boolean;
  sex: string;
  age: string;
}

const ruleForm = reactive<IRuleForm>({
  name: "",
  password: "",
  confirmPassword: "",
  phone: "",
  sex: "",
  age: "",
  rememberMe: false,
});
const ruleFormRef = ref<FormInstance>();
const rules = reactive<FormRules<IRuleForm>>({
  name: [{ required: true, message: "请输入名字", trigger: "blur" }],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
  confirmPassword: [
    { required: true, message: "请再次输入密码", trigger: "blur" },
  ],
  phone: [{ required: true, message: "请输入手机号", trigger: "blur" }],
  sex: [
    {
      required: true,
      message: "请选择性别",
      trigger: "change",
    },
  ],
});

const onRegister = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.validate((valid) => {
    if (valid) {
      console.log("submit!");
    } else {
      console.log("error submit!");
      return false;
    }
  });
};
const onLogin = () => {
  setState({ key: "panelType", value: "login" });
};
</script>
  
  <style lang='scss' scoped>
.no-password {
  color: #409eff;
}
::v-deep {
  .tool-content {
    .el-form-item__content {
      display: flex;
      justify-content: center;
      .el-button {
        flex: 1;
        height: 40px;
        line-height: 40px;

        border-radius: 10px;
        box-shadow: 0 6px 16px 0 rgb(78 111 242 / 30%);
        font-size: 17px;
        font-weight: 800;
        border: 0;
        color: #fff;
        cursor: pointer;
      }
    }
  }
  .remember-content {
    .el-form-item__content {
      display: flex;
      justify-content: space-between;
    }
  }
}
.register {
  .back-btn {
    display: flex;
    align-items: center;
    position: absolute;
    top: 10px;
    font-size: 12px;
    color: $blcolor;
    left: 10px;
    cursor: pointer;
  }
}
</style>
  